package foodmaterial.action;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import foodmaterial.action.valid.ObjectNullValid;
import foodmaterial.config.ChoiceDataSource;
import foodmaterial.dto.*;
import foodmaterial.entity.*;
import foodmaterial.excel.Excel;
import foodmaterial.service.InitService;
import foodmaterial.service.OrderService;
import foodmaterial.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.io.IOException;
import java.util.*;

@RequestMapping("/api/order")
@RestController
@CrossOrigin(allowCredentials = "true")
public class OrderAction extends BaseAction {
    @Autowired
    private OrderService service ;

    @Autowired
    private InitService initService ;

    @Autowired
    private Excel excel ;

    public static class TempOrderData {
        List<MealsType> customers ;

        @Valid
        List<OrdersDetail> details ;

        List<RecipeTemplate> recipeDetails ;

        @JsonFormat(pattern=Constants.DEFAULT_DATE_FORMAT,timezone="GMT+8")
        @ObjectNullValid(message = "就餐日期不能为空")
        Date eatDate ;
        @ObjectNullValid(message = "餐别不能为空")
        Long mealsTypeId ;
        Long customerId ;
        String orderType ;
        private Integer mealPersons ;

        public List<MealsType> getCustomers() {
            return customers;
        }

        public void setCustomers(List<MealsType> customers) {
            this.customers = customers;
        }

        public List<OrdersDetail> getDetails() {
            return details;
        }

        public void setDetails(List<OrdersDetail> details) {
            this.details = details;
        }

        public List<RecipeTemplate> getRecipeDetails() {
            return recipeDetails;
        }

        public void setRecipeDetails(List<RecipeTemplate> recipeDetails) {
            this.recipeDetails = recipeDetails;
        }

        public Date getEatDate() {
            return eatDate;
        }

        public void setEatDate(Date eatDate) {
            this.eatDate = eatDate;
        }

        public Long getMealsTypeId() {
            return mealsTypeId;
        }

        public void setMealsTypeId(Long mealsTypeId) {
            this.mealsTypeId = mealsTypeId;
        }

        public Long getCustomerId() {
            return customerId;
        }

        public void setCustomerId(Long customerId) {
            this.customerId = customerId;
        }

        public String getOrderType() {
            return orderType;
        }

        public void setOrderType(String orderType) {
            this.orderType = orderType;
        }

        public Integer getMealPersons() {
            return mealPersons;
        }

        public void setMealPersons(Integer mealPersons) {
            this.mealPersons = mealPersons;
        }
    }

    @PostMapping("/addMealsTypeTemplate")
    @ChoiceDataSource
    public JsonResult<String> addMealsTypeTemplate(@RequestBody @Valid MealsTypeTemplate mealsTypeTemplate,
                                                   BindingResult bindingResult) {
        JsonResult jsonResult = BindingResultUtil.error(bindingResult) ;
        if (jsonResult.getSuccess() == false) return jsonResult ;
        int result = service.addMealsTypeTemplate(mealsTypeTemplate) ;
        return result > 0 ? JsonResultTool.get(jsonResult,true, "新增模板成功") :
                JsonResultTool.get(jsonResult,false,"新增模板失败") ;
    }

    @PostMapping("/modifyMealsTypeTemplate")
    @ChoiceDataSource
    public JsonResult<String> modifyMealsTypeTemplate(@RequestBody @Valid MealsTypeTemplate mealsTypeTemplate,
                                                      BindingResult bindingResult) {
        JsonResult jsonResult = BindingResultUtil.error(bindingResult) ;
        if (jsonResult.getSuccess() == false) return jsonResult ;
        int result = service.modifyMealsTypeTemplate(mealsTypeTemplate) ;
        return result > 0 ? JsonResultTool.get(jsonResult,true, "修改模板成功") :
                JsonResultTool.get(jsonResult,false,"修改模板失败") ;
    }

    @GetMapping("/removeMealsTypeTemplate")
    @ChoiceDataSource
    public JsonResult<String> removeMealsTypeTemplate(Long id) {
        int result = service.removeMealsTypeTemplate(id) ;
        return result > 0 ? new JsonResult(true, "修改模板成功") :
                new JsonResult(false,"修改模板失败") ;
    }

    @PostMapping("/queryMealsTypeTemplate")
    @ChoiceDataSource
    public JsonResult<PageInfo<MealsTypeTemplate>> queryMealsTypeTemplate(
            @RequestBody MealsTypeTemplateDto dto) {
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize()) ;
        List<MealsTypeTemplate> result = service.queryMealsTypeTemplate(dto) ;
        PageInfo<MealsTypeTemplate> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true, ResultCode.SUCCESS,pageInfo) ;
    }

    @GetMapping("/queryMealsTypeTemplateDetails")
    @ChoiceDataSource
    public JsonResult<List<MealsTypeTemplateDetails>> queryMealsTypeTemplateDetails(Long templateId) {
        List<MealsTypeTemplateDetails> result = service.queryMealsTypeTemplateDetails(templateId) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/calculateExceed")
    @ChoiceDataSource
    public JsonResult<CalculateExceedResult> calculateExceed(@RequestBody CalculateExceedDto dto) {
        CalculateExceedResult result =  service.calculateExceed(dto);
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryMealsTypeTemplateDetailsBySupply")
    @ChoiceDataSource
    public JsonResult<List<FoodMaterial>> queryMealsTypeTemplateDetailsBySupply(
            @RequestBody MealsTypeTemplateDetailsDto dto) {
        List<FoodMaterial> result = service.queryMealsTypeTemplateDetailsBySupply(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryMealsTypeTemplateDetailsByVipSupply")
    @ChoiceDataSource
    public JsonResult<List<FoodMaterial>> queryMealsTypeTemplateDetailsByVipSupply(
            @RequestBody MealsTypeTemplateDetailsDto dto) {
        List<FoodMaterial> result = service.queryMealsTypeTemplateDetailsByVipSupply(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/addCustomerTeam")
    @ChoiceDataSource
    public JsonResult<String> addCustomerTeam(@RequestBody @Valid CustomerTeam customerTeam,
                                              BindingResult bindingResult) {
        JsonResult jsonResult = BindingResultUtil.error(bindingResult) ;
        if (jsonResult.getSuccess() == false) return jsonResult ;
        int result = service.addCustomerTeam(customerTeam) ;
        return result > 0 ? JsonResultTool.get(jsonResult,true, "新增分组成功") :
                JsonResultTool.get(jsonResult,false,"新增分组失败") ;
    }

    @PostMapping("/modifyCustomerTeam")
    @ChoiceDataSource
    public JsonResult<String> modifyCustomerTeam(@RequestBody @Valid CustomerTeam customerTeam,
                                                 BindingResult bindingResult) {
        JsonResult jsonResult = BindingResultUtil.error(bindingResult) ;
        if (jsonResult.getSuccess() == false) return jsonResult ;
        int result = service.modifyCustomerTeam(customerTeam) ;
        return result > 0 ? JsonResultTool.get(jsonResult,true, "修改分组成功") :
                JsonResultTool.get(jsonResult,false,"修改分组失败") ;
    }

    @GetMapping("/removeCustomerTeam")
    @ChoiceDataSource
    public JsonResult<String> removeCustomerTeam(Long id) {
        int result = service.removeCustomerTeam(id) ;
        return result > 0 ? new JsonResult(true, "删除分组成功") :
                new JsonResult(false,"删除分组失败") ;
    }

    @GetMapping("/removeCustomerTeamDetailsByDetailId")
    @ChoiceDataSource
    public JsonResult<String> removeCustomerTeamDetailsByDetailId(Long id) {
        int result = service.removeCustomerTeamDetailsByDetailId(id) ;
        return result > 0 ? new JsonResult(true, "从分组删除客户成功") :
                new JsonResult(false,"从分组删除客户失败") ;
    }

    @PostMapping("/addCustomerTeamDetails")
    @ChoiceDataSource
    public JsonResult<String> addCustomerTeamDetails(@RequestBody @Valid CustomerTeamDetails customerTeamDetails,
                           BindingResult bindingResult) {
        JsonResult jsonResult = BindingResultUtil.error(bindingResult) ;
        if (jsonResult.getSuccess() == false) return jsonResult ;
        int result = service.addCustomerTeamDetails(customerTeamDetails) ;
        return result > 0 ? JsonResultTool.get(jsonResult,true, "分组新增客户成功") :
                JsonResultTool.get(jsonResult,false,"分组新增客户失败") ;
    }

    @PostMapping("/queryCustomerTeam")
    @ChoiceDataSource
    public JsonResult<List<CustomerTeam>> queryCustomerTeam(@RequestBody CustomerTeam customerTeam) {
        List<CustomerTeam> result = service.queryCustomerTeam(customerTeam);
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryCustomerTeamDetails")
    @ChoiceDataSource
    public JsonResult<List<CustomerTeamDetails>> queryCustomerTeamDetails(@RequestBody Map<String,Object> params) {
        List<CustomerTeamDetails> result = service.queryCustomerTeamDetails(params);
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryCustomerTeamMealsType")
    @ChoiceDataSource
    public JsonResult<List<MealsType>> queryCustomerTeamMealsType(@RequestBody CustomerTeam customerTeam) {
        List<MealsType> result = service.queryCustomerTeamMealsType(customerTeam);
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/addOrders")
    @ChoiceDataSource
    public JsonResult<String> addOrders(@RequestBody TempOrderData data) {
        String result = service.addOrders(data) ;
        return StringUtils.isEmpty(result)  ? new JsonResult(true, "新增订单成功") :
                new JsonResult(false,result) ;
    }

    @PostMapping("/addDirectOrders")
    @ChoiceDataSource
    public JsonResult<String> addDirectOrders(@RequestBody TempOrderData data) {
        String result = service.addDirectOrders(data) ;
        return StringUtils.isEmpty(result)  ? new JsonResult(true, "新增订单成功") :
                new JsonResult(false,result) ;
    }

    @GetMapping("/removeOrders")
    @ChoiceDataSource
    public JsonResult<String> removeOrders(@RequestParam("orderId") Long orderId) {
        String result = service.removeOrders(orderId) ;
        return StringUtils.isEmpty(result) ? new JsonResult(true, "删除订单成功") :
                new JsonResult(false,result) ;
    }

    @PostMapping("/modifyOrders")
    @ChoiceDataSource
    public JsonResult<String> modifyOrders(@RequestBody @Valid Orders orders,BindingResult bindingResult) {
        JsonResult jsonResult = BindingResultUtil.error(bindingResult) ;
        if (jsonResult.getSuccess() == false) return jsonResult ;
        String result = service.modifyOrders(orders) ;
        return result == null ? JsonResultTool.get(jsonResult,true, "修改订单成功") :
                JsonResultTool.get(jsonResult,false,result) ;
    }

    @PostMapping("/copyOrders")
    @ChoiceDataSource
    public JsonResult<String> copyOrders(@RequestBody OrdersDto dto) {
        String result = service.copyOrders(dto) ;
        return result == null ? new JsonResult(true, "复制订单成功") :
                new JsonResult(false,result) ;
    }

    @PostMapping("/queryOrders")
    @ChoiceDataSource
    public JsonResult<PageInfo<Orders>> queryOrders(@RequestBody OrdersDto dto) {
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize()) ;
        List<Orders> result = service.queryOrders(dto) ;
        PageInfo<Orders> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true, ResultCode.SUCCESS,pageInfo) ;
    }

    @PostMapping("/queryTrackOrders")
    @ChoiceDataSource
    public JsonResult<PageInfo<Orders>> queryTrackOrders(@RequestBody TrackOrdersDto dto) {
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize()) ;
        List<Orders> result = service.queryTrackOrders(dto) ;
        PageInfo<Orders> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true, ResultCode.SUCCESS,pageInfo) ;
    }

    @GetMapping("/queryOrdersCount")
    @ChoiceDataSource
    public JsonResult<List<OrdersCount>> queryOrdersCount() {
        List<OrdersCount> result = service.queryOrdersCount() ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryRemoveOrders")
    @ChoiceDataSource
    public JsonResult<PageInfo<Orders>> queryRemoveOrders(@RequestBody OrdersDto dto) {
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize()) ;
        List<Orders> result = service.queryRemoveOrders(dto) ;
        PageInfo<Orders> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true, ResultCode.SUCCESS,pageInfo) ;
    }

    @GetMapping("/queryOrdersDetail")
    @ChoiceDataSource
    public JsonResult<List<OrdersDetail>> queryOrdersDetail(Long id) {
        List<OrdersDetail> result = service.queryOrdersDetail(id) ;
        return result.isEmpty()?
                new JsonResult(false, ResultCode.SUCCESS,null) :
                new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/queryOrdersRecipe")
    @ChoiceDataSource
    public JsonResult<List<OrdersRecipe>> queryOrdersRecipe(Long id) {
        List<OrdersRecipe> result = service.queryOrdersRecipe(id) ;
        return result.isEmpty()?
                new JsonResult(false, ResultCode.SUCCESS,null) :
                new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/queryRemoveOrdersDetail")
    @ChoiceDataSource
    public JsonResult<List<OrdersDetail>> queryRemoveOrdersDetail(Long id) {
        List<OrdersDetail> result = service.queryRemoveOrdersDetail(id) ;
        return result.isEmpty()?
                new JsonResult(false, ResultCode.SUCCESS,null) :
                new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/queryRemoveOrdersRecipe")
    @ChoiceDataSource
    public JsonResult<List<OrdersRecipe>> queryRemoveOrdersRecipe(Long id) {
        List<OrdersRecipe> result = service.queryRemoveOrdersRecipe(id) ;
        return result.isEmpty()?
                new JsonResult(false, ResultCode.SUCCESS,null) :
                new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/batchModifyOrdersPrice")
    @ChoiceDataSource
    public JsonResult<String> batchModifyOrdersPrice(@RequestBody BatchModifyOrdersPriceDto dto) {
        String result = service.batchModifyOrdersPrice(dto) ;
        return StringUtils.isEmpty(result) ? new JsonResult(true, "批量改价格成功") :
                new JsonResult(false,result) ;
    }

    @PostMapping("/supplyOutWareHouse")
    @ChoiceDataSource
    public JsonResult<String> supplyOutWareHouse(@RequestBody Map<String,List<Long>> orderIds) {
        String result = service.supplyOutWareHouse(orderIds.get("orderIds")) ;
        return StringUtils.isEmpty(result) ? new JsonResult(true, "配送出库成功") :
                new JsonResult(false,result) ;
    }

    @GetMapping("/print")
    public ModelAndView print(@RequestParam("ids") List<Long> ids,
                              @RequestParam("remarks") List<String> remarks,
                              @RequestParam("companyName") String companyName) {
        Map<String,Object> map = new HashMap<>();
        map.put("ordersIds",ids);
        map.put("remarks",remarks);
        map.put("companyName",companyName);
        map.put("backAddress",initService.querySysParamsByCode(Constants.BACK_SERVER_ADDRESS).getParamValue()) ;
        boolean kitchen = this.getSysUser().getFoodSupplyType().equals(Constants.KITCHEN_FOOD) ;
        return kitchen ? new ModelAndView("printRecipeOrders","params",map):
        new ModelAndView("printOrders","params",map);
    }

    @PostMapping("/printData")
    @ChoiceDataSource
    public JsonResult<List<Orders>> printData(
            @RequestParam("ordersIds") List<Long> ordersIds,
            @RequestParam("remarks") List<String> remarks) {
        List<Orders> result = service.print(ordersIds,remarks) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @RequestMapping("/printSupplySummary")
    public ModelAndView printSupplySummary(SupplySummaryBySupplyDto dto) {
        dto.setBackAddress(initService.querySysParamsByCode(Constants.BACK_SERVER_ADDRESS).getParamValue());
        return new ModelAndView("printSupplySummary","params",dto);
    }

    @RequestMapping("/printRecipeSupplySummary")
    public ModelAndView printRecipeSupplySummary(SupplySummaryBySupplyDto dto) {
        dto.setBackAddress(initService.querySysParamsByCode(Constants.BACK_SERVER_ADDRESS).getParamValue());
        return new ModelAndView("printRecipeSupplySummary","params",dto);
    }

    @RequestMapping("/printDistributionLabel")
    public ModelAndView printDistributionLabel(SupplySummaryBySupplyDto dto) {
        dto.setBackAddress(initService.querySysParamsByCode(Constants.BACK_SERVER_ADDRESS).getParamValue());
        return new ModelAndView("printDistributionLabel","params",dto);
    }

    @PostMapping("/queryPrintLabel")
    @ChoiceDataSource
    public JsonResult<List<OrdersDetail>> queryPrintLabel(@RequestBody SupplySummaryBySupplyDto dto) {
        List<OrdersDetail> result = service.queryPrintLabel(dto);
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryRecipePrintLabel")
    @ChoiceDataSource
    public JsonResult<List<OrdersRecipe>> queryRecipePrintLabel(@RequestBody SupplySummaryBySupplyDto dto) {
        List<OrdersRecipe> result = service.queryRecipePrintLabel(dto);
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @RequestMapping("/printRecipeDistributionLabel")
    public ModelAndView printRecipeDistributionLabel(SupplySummaryBySupplyDto dto) {
        dto.setBackAddress(initService.querySysParamsByCode(Constants.BACK_SERVER_ADDRESS).getParamValue());
        return new ModelAndView("printRecipeDistributionLabel","params",dto);
    }

    @RequestMapping("/printDistributionLabelWithSupplier")
    public ModelAndView printDistributionLabelWithSupplier(SupplySummaryBySupplierDto dto){
        dto.setBackAddress(initService.querySysParamsByCode(Constants.BACK_SERVER_ADDRESS).getParamValue());
        return new ModelAndView("printDistributionLabelWithSupplier","params",dto);
    }

    @PostMapping("/lockOrders")
    @ChoiceDataSource
    public JsonResult<String> lockOrders(@RequestBody LockOrderDto params) {
        int result = service.lockOrders(params) ;
        return result > 0 ? new JsonResult(true, "操作成功") :
                new JsonResult(false,"操作失败") ;

    }

    public static class SupplySummary {
        private List<String> header ;
        private List<Map<String,Object>> data ;

        public List<String> getHeader() {
            return header;
        }

        public void setHeader(Collection<String> col) {
            this.header = new ArrayList<>();
            this.header.addAll(col) ;
        }

        public List<Map<String, Object>> getData() {
            return data;
        }

        public void setData(List<Map<String, Object>> data) {
            this.data = data;
        }
    }

    @PostMapping("/querySupplySummaryByRouter")
    @ChoiceDataSource
    public JsonResult<SupplySummary> querySupplySummaryByRouter(@RequestBody SupplySummaryBySupplyDto dto) {
        SupplySummary result = service.querySupplySummaryByRouter(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryShowPrintLabel")
    @ChoiceDataSource
    public JsonResult<List<FoodMaterial>> queryShowPrintLabel(@RequestBody SupplySummaryBySupplyDto dto) {
        List<FoodMaterial> result = service.queryShowPrintLabel(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryRecipeShowPrintLabel")
    @ChoiceDataSource
    public JsonResult<List<RecipeTemplate>> queryRecipeShowPrintLabel(@RequestBody SupplySummaryBySupplyDto dto) {
        List<RecipeTemplate> result = service.queryRecipeShowPrintLabel(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySupplySummaryBySupplier")
    @ChoiceDataSource
    public JsonResult<SupplySummary> querySupplySummaryBySupplier(@RequestBody SupplySummaryBySupplierDto params) {
        SupplySummary result = service.querySupplySummaryBySupplier(params) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/downloadDistributionSummary")
    @ChoiceDataSource
    public void downloadDistributionSummary(SupplySummaryBySupplyDto dto,
            HttpServletResponse response) throws IOException {
        setDownload(response,excel);
        excel.downloadDistributionSummaryExcel(dto,
                Constants.EXCEL_DISTRIBUTION_SUMMARY_TEMPLATE,response.getOutputStream(),service);
    }

    @GetMapping("/downloadRecipeDistributionSummary")
    @ChoiceDataSource
    public void downloadRecipeDistributionSummary(SupplySummaryBySupplyDto dto,
                                            HttpServletResponse response) throws IOException {
        setDownload(response,excel);
        excel.downloadRecipeDistributionSummaryExcel(dto,
                Constants.EXCEL_RECIPE_DISTRIBUTION_SUMMARY_TEMPLATE,response.getOutputStream(),service);
    }

    @PostMapping("/batchModifyOrdersDistributionDate")
    @ChoiceDataSource
    public JsonResult<String> batchModifyOrdersDistributionDate(@RequestBody BatchModifyOrdersDistributionDateDto dto) {
        int result = service.batchModifyOrdersDistributionDate(dto);
        return result > 0 ? new JsonResult(true, "修改成功") :
                new JsonResult(false,"没有符合条件的订单") ;
    }

    @PostMapping("/queryOrderDetailsByDistributionDateAndRouter")
    @ChoiceDataSource
    public JsonResult<OrderAction.SupplySummary> queryOrderDetailsByDistributionDateAndRouter(
            @RequestBody DistributionDateAndRouterDto dto) {
        return new JsonResult(true,ResultCode.SUCCESS,service.queryOrderDetailsByDistributionDateAndRouter(dto)) ;
    }

    @GetMapping("/downloadOrderDetailsByDistributionDateAndRouter")
    @ChoiceDataSource
    public void downloadOrderDetailsByDistributionDateAndRouter(
            DistributionDateAndRouterDto dto,
            HttpServletResponse response) throws IOException{
        setDownload(response,excel);
        excel.downloadOrderDetailsByDistributionDateAndRouterExcel(dto,
                Constants.EXCEL_ORDER_DETAILS_DISTRIBUTION_DATE_ROUTER,response.getOutputStream(),service);
    }

    @PostMapping("/queryReminder")
    @ChoiceDataSource
    public JsonResult<PageInfo<Map<String, Object>>> queryReminder(@RequestBody ReminderDto reminderDto) {
        PageHelper.startPage(reminderDto.getPageNo(),reminderDto.getPageSize()) ;
        List<Map<String, Object>> result = service.queryReminder(reminderDto) ;
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true,ResultCode.SUCCESS,pageInfo) ;
    }

    @PostMapping("/queryExceed")
    @ChoiceDataSource
    public JsonResult<PageInfo<Map<String, Object>>> queryExceed(@RequestBody ExceedDto dto) {
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize()) ;
        List<Map<String, Object>> result = service.queryExceed(dto) ;
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true,ResultCode.SUCCESS,pageInfo) ;
    }

    @PostMapping("/foodProduct")
    @ChoiceDataSource
    public JsonResult<List<FoodProduct>> foodProduct(@RequestBody FoodProductDto dto) {
        List<FoodProduct> result = service.foodProduct(dto) ;
        return new JsonResult(true,ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/downloadFoodProduct")
    @ChoiceDataSource
    public void downloadFoodProduct(FoodProductDto dto,
                                     HttpServletResponse response) throws IOException {
        setDownload(response,excel);
        excel.downloadFoodProductExcel(dto,
                Constants.EXCEL_FOOD_PRODUCT_TEMPLATE,response.getOutputStream(),service);
    }

}
